package customfields;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class InformationField extends Field{
	
	private String text;
	private int height;
	private int width;
	private int padding = 10;
	private int textColorUnfocused = Color.BLACK;
	private int textColorFocused = Color.WHITE;
	private int textColor;
	private Bitmap img;
	
	public InformationField(String txt, String image, long style){
		super(style);
		this.text = txt;
		height = (int) (getFont().getHeight()*1.5);  
		width = (int) (Display.getWidth()*0.75); 
		img = Bitmap.getBitmapResource(image);
	}
	
	public InformationField(String txt, String image, long style, int w, int h){
		super(style);
		this.text = txt;
		height = w;  
		width = h; 
		img = Bitmap.getBitmapResource(image);
	}
	
	public InformationField(String txt, String image){
		super();
		this.text=txt;
		height = (int) (getFont().getHeight()*1.5);  
		width = (int) (Display.getWidth()*0.75); 
		img = Bitmap.getBitmapResource(image);
	}
	
	public InformationField(String txt, String image, long style, int color){
		super(style);
		this.text = txt;
		height = (int) (getFont().getHeight()*1.5);  
		width = (int) (Display.getWidth()*0.5); 
		img = Bitmap.getBitmapResource(image);
		textColor=color;
	}

	public int getPreferredWidth() {  
		return width;  
	}  

	public int getPreferredHeight() {  
		return height;  
	}  
	
	protected void onFocus(int direction) {
		textColor = textColorFocused; 
		invalidate();  
	}  

	protected void onUnfocus() {  
		textColor = textColorUnfocused;  
		invalidate();  
	} 

	protected void layout(int arg0, int arg1) {  
		setExtent(getPreferredWidth(), getPreferredHeight());  
	}  

	protected void paint(Graphics graphics) {
		// left bitmap
		graphics.drawBitmap(padding/2,padding/2,25,20,img,0,0);
		// right text
		graphics.setColor(textColor);
		graphics.drawText(text,25+padding,padding/2);  

	}
	

	protected boolean navigationClick(int status, int time){
		return true;
	}
	protected boolean navigationUnclick(int status, int time){
		return true;
	}

}
